package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC303 {
    public long startExecuteTime = System.currentTimeMillis();


    class NumArray {

        int[] preSumArray;

        public NumArray(int[] nums) {
            this.preSumArray = new int[nums.length + 1];
            for (int i = 1; i <= nums.length; i++) {
                preSumArray[i] += nums[i - 1] + preSumArray[i - 1];
            }
        }

        public int sumRange(int i, int j) {
            return preSumArray[j + 1] - preSumArray[i];
        }
    }

    /**
     * Your NumArray object will be instantiated and called as such:
     * NumArray obj = new NumArray(nums);
     * int param_1 = obj.sumRange(i,j);
     */

    public void run() {
        int[] arr = InputUtil.toIntegerArray("[-2,0,3,-5,2,-1]");
        NumArray solution = new NumArray(arr);
        System.out.println(solution.sumRange(0, 2));
    }

    public static void main(String[] args) throws Exception {
        LC303 an = new LC303();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
